package com.ogawa.joypal.user.viewmodel

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.LogUtils
import com.ogawa.base.base.BaseViewModel
import com.ogawa.base.bean.LoadState
import com.ogawa.projectcommon.utils.dataConvert
import com.ogawa.projectcommon.utils.launch
import com.ogawa.joypal.user.bean.UserFeedBacksRequest
import com.ogawa.projectcommon.network.RetrofitManager
import com.ogawa.joypal.user.service.UserApiService
import com.ogawa.projectcommon.constants.Constant
import kotlinx.coroutines.cancel

class LoginSuggestViewModel : BaseViewModel() {
    var mUserFeedBacksRequest = UserFeedBacksRequest()
    var state = MutableLiveData<String>()


    fun userFeedBacks() {
        launch({
            loadState.value = LoadState.Loading("")
            RetrofitManager.INSTANCE.createService(UserApiService::class.java)
                .userFeedBacks(mUserFeedBacksRequest)
                .dataConvert()
            state.value = Constant.SUCCESS
            loadState.value = LoadState.Success("")
        }
            , { loadState.value = LoadState.Fail(it.message ?: "") }
            , {})
    }




    //不需要，在ViewModel销毁时候会自己清除
    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    open fun onDestroy() {
        LogUtils.e("onDestroy")
        viewModelScope.cancel()
    }


}
